import Vue from 'vue'
import Vuex from 'vuex'
import axios from "@/axios";
Vue.use(Vuex)

export default {
    state: {
        user: {}
    },
    mutations: {
        setUserInfo(state) {
            if (!localStorage.getItem("token")) {
                return;
            }
            // console.log(localStorage.getItem("userinfo"))
            if (!localStorage.getItem("userinfo")) {
                axios.get("/sys/userInfo")
                    .then(res => {
                        state.user = res.data.data
                        localStorage.setItem("userinfo", JSON.stringify(state.user));
                    })
            } else {
                state.user = JSON.parse(localStorage.getItem("userinfo"));
                // console.log(state.user)
            }
        },
        resetUserInfoState(state) {
            state.user = {};
        }
    }
}